package cn.iocoder.yudao.module.yyzx.service.nurse_record;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_record.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_record.Nurse_recordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.service.outgoing.mysql.nurse_record.Nurse_recordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 护理记录 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class Nurse_recordServiceImpl implements Nurse_recordService {

    @Resource
    private Nurse_recordMapper nurse_recordMapper;

    @Override
    public Integer createNurse_record(Nurse_recordSaveReqVO createReqVO) {
        // 插入
        Nurse_recordDO nurse_record = BeanUtils.toBean(createReqVO, Nurse_recordDO.class);
        nurse_recordMapper.insert(nurse_record);
        // 返回
        return nurse_record.getId();
    }

    @Override
    public void updateNurse_record(Nurse_recordSaveReqVO updateReqVO) {
        // 校验存在
        validateNurse_recordExists(updateReqVO.getId());
        // 更新
        Nurse_recordDO updateObj = BeanUtils.toBean(updateReqVO, Nurse_recordDO.class);
        nurse_recordMapper.updateById(updateObj);
    }

    @Override
    public void deleteNurse_record(Integer id) {
        // 校验存在
        validateNurse_recordExists(id);
        // 删除
        nurse_recordMapper.deleteById(id);
    }

    private void validateNurse_recordExists(Integer id) {
        if (nurse_recordMapper.selectById(id) == null) {
            throw exception(NURSE_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public Nurse_recordDO getNurse_record(Integer id) {
        return nurse_recordMapper.selectById(id);
    }

    @Override
    public PageResult<Nurse_recordDO> getNurse_recordPage(Nurse_recordPageReqVO pageReqVO) {
        return nurse_recordMapper.selectPage(pageReqVO);
    }

}